﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Benefit.Models.View
{
    /// <summary>
    /// 交易员日品种交易情况
    /// </summary>
    public class OperatorDayProductInfo
    {
        public int Id { get; set; }
        public int OperatorId { get; set; }
        public virtual Sys.Operator Operator { get; set; }
        public int TradeHistoryId { get; set; }
        public virtual Sys.TradeHistory TradeHistory { get; set; }
        public string ProductId { get; set; }

        /// <summary>
        /// 多空方向
        /// </summary>
        public string Direction { get; set; }
        /// <summary>
        /// 盈利/亏损
        /// </summary>
        public string WinOrLost { get; set; }

        /// <summary>
        /// 平仓盈亏
        /// </summary>
        public double Profit { get; set; }
        /// <summary>
        /// 手续费
        /// </summary>
        public double Free { get; set; }
        /// <summary>
        /// 净收益
        /// </summary>
        public double DayCount { get; set; }
        /// <summary>
        /// 交易笔数
        /// </summary>
        public double BillCount { get; set; }
        /// <summary>
        /// 总亏损
        /// </summary>
        public double SumLost { get; set; }
        /// <summary>
        /// 总盈利
        /// </summary>
        public double SumWin { get; set; }
        /// <summary>
        /// 保证金占用
        /// </summary>
        public double UsedMargin { get; set; }
        /// <summary>
        /// 盈利次数
        /// </summary>
        public int WinCount { get; set; }
        /// <summary>
        /// 亏损次数
        /// </summary>
        public int LoseCount { get; set; }
        /// <summary>
        /// 单笔收益
        /// </summary>
        public double AvgBillProfit { get; set; }

        public double Percent { get; set; }

        ///// <summary>
        ///// 获取处理过的交易员品种交易信息(这个方法不用加工)
        ///// </summary>
        ///// <param name="tradeHistoryId"></param>
        ///// <param name="operatorid"></param>
        ///// <param name="db"></param>
        ///// <returns></returns>
        //public List<OperatorDayProductInfo> GetSortedOperatorDayProductInfo(int tradeHistoryId, int operatorid, DB.DBManager db)
        //{
        //    List<OperatorDayProductInfo> returninfos = new List<OperatorDayProductInfo>();
        //    List<OperatorDayProductInfo> infos = GetOperatorDayProductInfo(tradeHistoryId, operatorid, db);
        //    List<string> products = new List<string>();
        //    foreach (OperatorDayProductInfo _info in infos)
        //    {
        //        var query = products.Where(t => t.Equals(_info.ProductId));
        //        if (query.Count() == 0)
        //        {
        //            products.Add(_info.ProductId);
        //        }
        //    }
        //    foreach (string product in products)
        //    {
        //        #region 获取品种总的信息
        //        OperatorDayProductInfo info = new OperatorDayProductInfo();
        //        info.ProductId = product;
        //        info.BillCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Sum(a => a.BillCount);
        //        info.DayCount = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Sum(a => a.DayCount), 2);
        //        info.Direction = "-";
        //        info.Free = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Sum(a => a.Free), 2);
        //        info.LoseCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Sum(a => a.LoseCount);
        //        info.Profit = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Sum(a => a.Profit), 2);
        //        info.SumLost = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Sum(a => a.SumLost), 2);
        //        info.SumWin = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Sum(a => a.SumWin), 2);
        //        info.UsedMargin = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Sum(a => a.UsedMargin), 2);
        //        info.WinCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Sum(a => a.WinCount);
        //        if (info.BillCount > 0)
        //        {
        //            info.AvgBillProfit = Math.Round((info.SumWin - info.SumLost) / info.BillCount, 2);
        //        }
        //        else
        //        {
        //            info.AvgBillProfit = 0;
        //        }
        //        info.WinOrLost = "-";
        //        returninfos.Add(info);
        //        #endregion

        //        #region 品种多头总的情况
        //        OperatorDayProductInfo info2 = new OperatorDayProductInfo();
        //        info2.ProductId = product + "_#1";
        //        info2.BillCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Sum(a => a.BillCount);
        //        info2.DayCount = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Sum(a => a.DayCount), 2);
        //        info2.Direction = "多头";
        //        info2.Free = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Sum(a => a.Free), 2);
        //        info2.LoseCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Sum(a => a.LoseCount);
        //        info2.Profit = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Sum(a => a.Profit), 2);
        //        info2.SumLost = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Sum(a => a.SumLost), 2);
        //        info2.SumWin = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Sum(a => a.SumWin), 2);
        //        info2.UsedMargin = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Sum(a => a.UsedMargin), 2);
        //        info2.WinCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Sum(a => a.WinCount);
        //        info2.WinOrLost = "-";
        //        if (info2.BillCount > 0)
        //        {
        //            info2.AvgBillProfit = Math.Round((info2.SumWin - info2.SumLost) / info2.BillCount, 2);
        //        }
        //        else
        //        {
        //            info2.AvgBillProfit = 0;
        //        }
        //        returninfos.Add(info2);
        //        #endregion

        //        #region 品种多头 盈利 的情况
        //        OperatorDayProductInfo info3 = new OperatorDayProductInfo();
        //        info3.ProductId = product + "_#1";
        //        info3.BillCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit > 0).Sum(a => a.BillCount);
        //        info3.DayCount = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit > 0).Sum(a => a.DayCount), 2);
        //        info3.Direction = "-";
        //        info3.Free = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit > 0).Sum(a => a.Free), 2);
        //        info3.LoseCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit > 0).Sum(a => a.LoseCount);
        //        info3.Profit = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit > 0).Sum(a => a.Profit), 2);
        //        info3.SumLost = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit > 0).Sum(a => a.SumLost), 2);
        //        info3.SumWin = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit > 0).Sum(a => a.SumWin), 2);
        //        info3.UsedMargin = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit > 0).Sum(a => a.UsedMargin), 2);
        //        info3.WinCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit > 0).Sum(a => a.WinCount);
        //        info3.WinOrLost = "盈利";
        //        if (info3.BillCount > 0)
        //        {
        //            info3.AvgBillProfit = Math.Round((info3.SumWin - info3.SumLost) / info3.BillCount, 2);
        //        }
        //        else
        //        {
        //            info3.AvgBillProfit = 0;
        //        }
        //        returninfos.Add(info3);
        //        #endregion

        //        #region 品种多头 亏损 的情况
        //        OperatorDayProductInfo info4 = new OperatorDayProductInfo();
        //        info4.ProductId = product + "_#1";
        //        info4.BillCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit <= 0).Sum(a => a.BillCount);
        //        info4.DayCount = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit <= 0).Sum(a => a.DayCount), 2);
        //        info4.Direction = "-";
        //        info4.Free = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit < 0).Sum(a => a.Free), 2);
        //        info4.LoseCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit < 0).Sum(a => a.LoseCount);
        //        info4.Profit = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit < 0).Sum(a => a.Profit), 2);
        //        info4.SumLost = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit < 0).Sum(a => a.SumLost), 2);
        //        info4.SumWin = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit < 0).Sum(a => a.SumWin), 2);
        //        info4.UsedMargin = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit < 0).Sum(a => a.UsedMargin), 2);
        //        info4.WinCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("多头")).Where(a => a.Profit < 0).Sum(a => a.WinCount);
        //        info4.WinOrLost = "亏损";
        //        if (info4.BillCount > 0)
        //        {
        //            info4.AvgBillProfit = Math.Round((info4.SumWin - info4.SumLost) / info4.BillCount, 2);
        //        }
        //        else
        //        {
        //            info4.AvgBillProfit = 0;
        //        }
        //        returninfos.Add(info4);
        //        #endregion


        //        #region 品种空头总的情况
        //        OperatorDayProductInfo info5 = new OperatorDayProductInfo();
        //        info5.ProductId = product + "_#1";
        //        info5.BillCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Sum(a => a.BillCount);
        //        info5.DayCount = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Sum(a => a.DayCount), 2);
        //        info5.Direction = "空头";
        //        info5.Free = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Sum(a => a.Free), 2);
        //        info5.LoseCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Sum(a => a.LoseCount);
        //        info5.Profit = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Sum(a => a.Profit), 2);
        //        info5.SumLost = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Sum(a => a.SumLost), 2);
        //        info5.SumWin = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Sum(a => a.SumWin), 2);
        //        info5.UsedMargin = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Sum(a => a.UsedMargin), 2);
        //        info5.WinCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Sum(a => a.WinCount);
        //        info5.WinOrLost = "-";
        //        if (info5.BillCount > 0)
        //        {
        //            info5.AvgBillProfit = Math.Round((info5.SumWin - info5.SumLost) / info5.BillCount, 2);
        //        }
        //        else
        //        {
        //            info5.AvgBillProfit = 0;
        //        }
        //        returninfos.Add(info5);
        //        #endregion

        //        #region 品种空头 盈利 的情况
        //        OperatorDayProductInfo info6 = new OperatorDayProductInfo();
        //        info6.ProductId = product + "_#1";
        //        info6.BillCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit > 0).Sum(a => a.BillCount);
        //        info6.DayCount = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit > 0).Sum(a => a.DayCount), 2);
        //        info6.Direction = "-";
        //        info6.Free = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit > 0).Sum(a => a.Free), 2);
        //        info6.LoseCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit > 0).Sum(a => a.LoseCount);
        //        info6.Profit = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit > 0).Sum(a => a.Profit), 2);
        //        info6.SumLost = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit > 0).Sum(a => a.SumLost), 2);
        //        info6.SumWin = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit > 0).Sum(a => a.SumWin), 2);
        //        info3.UsedMargin = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit > 0).Sum(a => a.UsedMargin), 2);
        //        info6.WinCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit > 0).Sum(a => a.WinCount);
        //        info6.WinOrLost = "盈利";
        //        if (info6.BillCount > 0)
        //        {
        //            info6.AvgBillProfit = Math.Round((info6.SumWin - info6.SumLost) / info6.BillCount, 2);
        //        }
        //        else
        //        {
        //            info6.AvgBillProfit = 0;
        //        }
        //        returninfos.Add(info6);
        //        #endregion

        //        #region 品种空头 亏损 的情况
        //        OperatorDayProductInfo info7 = new OperatorDayProductInfo();
        //        info7.ProductId = product + "_#1";
        //        info7.BillCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit < 0).Sum(a => a.BillCount);
        //        info7.DayCount = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit < 0).Sum(a => a.DayCount), 2);
        //        info7.Direction = "-";
        //        info7.Free = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit < 0).Sum(a => a.Free), 2);
        //        info7.LoseCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit < 0).Sum(a => a.LoseCount);
        //        info7.Profit = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit < 0).Sum(a => a.Profit), 2);
        //        info7.SumLost = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit < 0).Sum(a => a.SumLost), 2);
        //        info7.SumWin = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit < 0).Sum(a => a.SumWin), 2);
        //        info7.UsedMargin = Math.Round(infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit < 0).Sum(a => a.UsedMargin), 2);
        //        info7.WinCount = infos.Where(a => a.ProductId.Equals(info.ProductId)).Where(a => a.Direction.Equals("空头")).Where(a => a.Profit < 0).Sum(a => a.WinCount);
        //        info7.WinOrLost = "亏损";
        //        if (info7.BillCount > 0)
        //        {
        //            info7.AvgBillProfit = Math.Round((info7.SumWin - info7.SumLost) / info7.BillCount, 2);
        //        }
        //        else
        //        {
        //            info7.AvgBillProfit = 0;
        //        }
        //        returninfos.Add(info7);
        //        #endregion


        //    }



        //    return returninfos;
        //}

        ///// <summary>
        ///// 得到不分多空方向的品种交易信息
        ///// </summary>
        ///// <param name="tradeHistoryId"></param>
        ///// <param name="operatorid"></param>
        ///// <returns></returns>
        //public List<OperatorDayProductInfo> GetOperatorDayProductInfoIgnoreDirection(int tradeHistoryId, int operatorid, DB.DBManager db)
        //{
        //    List<OperatorDayProductInfo> infos = GetOperatorDayProductInfo(tradeHistoryId, operatorid, db);
        //    List<OperatorDayProductInfo> returninfos = new List<OperatorDayProductInfo>();
        //    foreach (OperatorDayProductInfo info in infos)
        //    {
        //        OperatorDayProductInfo _info = new OperatorDayProductInfo();
        //        _info.ProductId = info.ProductId;
        //        var query = returninfos.Where(a => a.ProductId.Equals(_info.ProductId));
        //        if (query.Count() > 0)
        //        {

        //            query.First().BillCount += info.BillCount;
        //            query.First().DayCount += info.DayCount;
        //            query.First().Free += info.Free;
        //            query.First().LoseCount += info.LoseCount;
        //            query.First().Percent += info.Percent;
        //            query.First().ProductId = info.ProductId;
        //            query.First().Profit += info.Profit;
        //            query.First().SumLost += info.SumLost;
        //            query.First().SumWin += info.SumWin;
        //            query.First().TradeHistoryId = info.TradeHistoryId;
        //            query.First().UsedMargin += info.UsedMargin;
        //            query.First().WinCount += info.WinCount;
        //            query.First().WinOrLost = info.WinOrLost;
        //        }
        //        else
        //        {
        //            _info = info;
        //            returninfos.Add(_info);
        //        }

        //    }
        //    return returninfos;
        //}

        ///// <summary>
        ///// 得到分多空方向的品种交易信息
        ///// </summary>
        ///// <param name="tradeHistoryId"></param>
        ///// <param name="operatorid"></param>
        ///// <returns></returns>
        //public List<OperatorDayProductInfo> GetOperatorDayProductInfo(int tradeHistoryId, int operatorid, DB.DBManager db)
        //{
        //    return db.OperatorDayProductInfo.Where(a => a.TradeHistoryId == tradeHistoryId).Where(a => a.OperatorId == operatorid).ToList();
        //}

        ///// <summary>
        ///// 得到分多空方向的品种交易信息
        ///// </summary>
        ///// <param name="tradeHistoryId"></param>
        ///// <param name="operatorid"></param>
        ///// <returns></returns>
        //public List<OperatorDayProductInfo> GetOperatorMonthProductInfo(int month, int year, int operatorid, DB.DBManager db)
        //{
        //    return db.OperatorDayProductInfo.Where(a => a.TradeHistory.MPdate == month).Where(a => a.TradeHistory.YPdate == year).Where(a => a.OperatorId == operatorid).ToList();
        //}

        ///// <summary>
        ///// 得到分多空方向的品种交易信息
        ///// </summary>
        ///// <param name="tradeHistoryId"></param>
        ///// <param name="operatorid"></param>
        ///// <returns></returns>
        //public void IntiOperatorDayProductInfo(int tradeHistoryId, DB.DBManager db)
        //{
        //    List<OperatorDayProductInfo> infos = new List<OperatorDayProductInfo>();
        //    Sys.TradeHistory th = new Sys.TradeHistory();

        //    List<Sys.Operator> operators = new Sys.Operator().GetList(db);
        //    foreach (Sys.Operator op in operators)
        //    {
        //        int operatorid = op.Id;
        //        List<Sys.Account> accounts = new Sys.DayOperatorAccount().GetDayOperatorAccounts(th.GetDateTimeFromTradeHistoryId(tradeHistoryId, db), operatorid, db);
        //        foreach (Sys.Account account in accounts)
        //        {
        //            Data.Day.AccountDayTradeProduct product = new Data.Day.AccountDayTradeProduct();
        //            List<Data.Day.AccountDayTradeProduct> ap = product.GetAccountDayTradeProduct(account.Id, tradeHistoryId, db);
        //            foreach (Data.Day.AccountDayTradeProduct p in ap)
        //            {
        //                var productquery = (from t in db.Product where t.Id == p.ProductId select t).ToList();

        //                var query = from t in infos where t.ProductId.Equals(productquery.First().ProductId) && t.Direction.Equals(p.Direction) select t;
        //                if (query.Count() == 0)//把新的品种信息加入列表
        //                {
        //                    OperatorDayProductInfo info = FenZhuangShuJu(p, productquery.First().ProductId);
        //                    info.OperatorId = op.Id;
        //                    infos.Add(info);
        //                }
        //                else//累加旧的列表
        //                {
        //                    if (p.Direction == 1)//空头
        //                    {
        //                        query = infos.Where(a => a.Direction.Equals("空头"));
        //                    }
        //                    else//多头
        //                    {
        //                        query = infos.Where(a => a.Direction.Equals("多头"));
        //                    }
        //                    if (query.Count() > 0)
        //                    {
        //                        var _query = query.First();
        //                        _query.DayCount += p.DayCount;
        //                        _query.Free += p.Free;
        //                        _query.LoseCount += p.LoseCount;
        //                        _query.SumLost += p.SumLost;
        //                        _query.SumWin += p.SumWin;
        //                        _query.UsedMargin += p.UsedMargin;
        //                        _query.WinCount += p.WinCount;
        //                        _query.Profit += p.Profit;
        //                        _query.BillCount += p.BillCount;
        //                        //    _query.Percent += Convert.ToInt32((_query.Profit / allSum) * 100);
        //                    }
        //                    else
        //                    {
        //                        OperatorDayProductInfo info = FenZhuangShuJu(p, productquery.First().ProductId);
        //                        //   info.Percent = Convert.ToInt32((info.Profit / allSum) * 100);
        //                        infos.Add(info);
        //                    }

        //                }
        //            }
        //        }

        //        foreach (OperatorDayProductInfo info in infos)
        //        {
        //            var allSum = infos.Where(a => a.OperatorId == info.OperatorId).Sum(a => a.Profit);
        //            info.Percent = Convert.ToInt32((info.Profit / Math.Abs(allSum)) * 100);
        //            db.OperatorDayProductInfo.Add(info);
        //        }
        //    }
        //    db.SaveChanges();
        //}
        //public List<OperatorDayProductInfo> GetOperatorDayProductInfo(int tradeHistoryId, int operatorid, bool win, DB.DBManager db)
        //{
        //    if (win)
        //    {
        //        return db.OperatorDayProductInfo.Where(a => a.TradeHistoryId == tradeHistoryId).Where(a => a.OperatorId == operatorid).Where(a => a.Profit > 0).ToList();
        //    }
        //    else
        //    {
        //        return db.OperatorDayProductInfo.Where(a => a.TradeHistoryId == tradeHistoryId).Where(a => a.OperatorId == operatorid).Where(a => a.Profit <= 0).ToList();
        //    }
        //}

        //public void Delete(int tradeHistoryId, DB.DBManager db)
        //{
        //    var query = db.OperatorDayProductInfo.Where(a => a.TradeHistoryId == tradeHistoryId);
        //    foreach (OperatorDayProductInfo info in query)
        //    {
        //        db.OperatorDayProductInfo.Remove(info);
        //    }
        //    db.SaveChanges();
        //}
        //private OperatorDayProductInfo FenZhuangShuJu(Data.Day.AccountDayTradeProduct p, string productid)
        //{
        //    OperatorDayProductInfo info = new OperatorDayProductInfo();
        //    info.DayCount = p.DayCount;
        //    if (p.Direction == 1)
        //    {
        //        info.Direction = "空头";
        //    }
        //    else
        //    {
        //        info.Direction = "多头";
        //    }
        //    info.Free = p.Free;
        //    info.LoseCount = p.LoseCount;
        //    info.SumLost = p.SumLost;
        //    info.SumWin = p.SumWin;
        //    info.UsedMargin = p.UsedMargin;
        //    info.WinCount = p.WinCount;
        //    info.Profit = p.Profit;
        //    info.BillCount = p.BillCount;
        //    info.ProductId = productid;
        //    info.TradeHistoryId = p.TradeHistoryId;
        //    info.Percent = 1;
        //    if (p.Profit > 0)
        //    {
        //        info.WinOrLost = "盈利";
        //    }
        //    else
        //    {
        //        info.WinOrLost = "亏损";
        //    }
        //    return info;
        //}
    }
}
